import { defineStore } from 'pinia'
interface State {
  isCollapse: boolean
  activedTaskId: number | null
  battle: BattleForm | null
  showBattleList: boolean
  showImportList: boolean
  showSatelliteList: boolean
  showToolBox: boolean
  showSatelliteMsgBox: boolean
  selectedSatellite: SatelliteDetail | null
}
export const useLayoutStore = defineStore('layout-store', {
  state: (): State => {
    return {
      isCollapse: false,
      activedTaskId: null,
      battle: null,
      showBattleList: false,
      showImportList: false,
      showSatelliteList: false,
      showToolBox: true,
      showSatelliteMsgBox: false,
      selectedSatellite: null,
    }
  },
  actions: {
    toggleCollapse(isCollapse: boolean) {
      this.isCollapse = isCollapse
    },
    setActivedTaskId(activedTaskId: number | null) {
      this.activedTaskId = activedTaskId
      this.showToolBox = false
    },
    setActivedBattle(battle: BattleForm) {
      this.battle = battle
    },
    toggleShowBattleList(show: boolean) {
      this.showBattleList = show
      if (show) {
        this.showSatelliteList = false
      }
    },
    toggleShowImportList(show: boolean) {
      this.showImportList = show
      if (show) {
        this.showSatelliteList = false
      }
    },
    toggleShowSatelliteList(show: boolean) {
      this.showSatelliteList = show
      if (show) {
        this.showBattleList = false
        this.showImportList = false
      }
    },
    toggleShowToolBox(activeTab: string) {
      if (activeTab === '整体态势视图') {
        this.showToolBox = true
      } else {
        this.showToolBox = false
        this.showSatelliteList = false
        this.showBattleList = false
        this.showImportList = false
      }
    },
    setSelectedSatellite(satellite: SatelliteDetail | null) {
      this.selectedSatellite = satellite
    },
    /* 关闭面板 */
    closeSatPanel() {
      this.showSatelliteMsgBox = false
      this.showSatelliteList = false
      this.showBattleList = false
      this.showImportList = false
    },
  },
  persist: {
    storage: localStorage,
    pick: ['activedTaskId', 'battle'],
  },
})
